fn main() {
    test_int_var_copy();
    test_access_moved_str();
    test_access_copy_str();
    test_return_ownership_and_more_var();
}

fn test_int_var_copy() {
    let x = 5;
    let mut y = x;
    y += 1;
    println!("Hello, var mov and copy!");
    println!("x = {x}");
    println!("y = {y}");
}

fn test_access_moved_str() {
    let s1 = String::from("hello");
    let s2 = s1;

    // s1 ownership have been to s2
    // so we can not access s1, after it ownership move to another var.
    println!("{s2}, world!");
}

fn test_access_copy_str() {
    let s1 = String::from("hello");
    let s2 = s1.clone();

    println!("s1 = {}, s2 = {}", s1, s2);
}

fn test_return_ownership_and_more_var() {
    let s1 = String::from("hello");

    let (s2, len) = calculate_length(s1);

    println!("The length of '{}' is {}.", s2, len);
}

fn calculate_length(s: String) -> (String, usize) {
    let length = s.len(); // len() returns the length of a String

    (s, length)
}
